package mail.util;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Wrapper for a single mail.
 * 
 * @author Ankan
 */
public class Mail {

    private String from, to, body, subj;

    public Mail() {
        from = "";
        to = "";
        body = "";
        subj = "";
    }

    /**
     * Returns a visual JPanel view of this email.
     * 
     * @return 
     */
    public JPanel getView() {
        JPanel view = new JPanel();
        JPanel top = new JPanel();
        view.setLayout(new BorderLayout());
        JLabel label = new JLabel();
        label.setText("From: " + from);
        top.setLayout(new GridLayout(3, 1));
        top.add(label);
        label = new JLabel("To: " + to);
        top.add(label);
        label = new JLabel("Subject: " + subj);
        top.add(label);
        view.add(top, BorderLayout.NORTH);
        label = new JLabel(body);
        view.add(label, BorderLayout.CENTER);
        view.setSize(100, 100);
        view.setVisible(true);
        return view;
    }
    //getters and setters
    public void setBody(String body) {
        this.body = body;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public void setSubj(String subj) {
        this.subj = subj;
    }

    public void setTo(String to) {
        this.to = to;
    }

    public String getBody() {
        return body;
    }

    public String getFrom() {
        return from;
    }

    public String getSubj() {
        return subj;
    }

    public String getTo() {
        return to;
    }

    /**
     * Creates a new mail
     * 
     * @param from
     * @param to
     * @param body
     * @param subj 
     */
    public Mail(String from, String to, String body, String subj) {
        this.from = from;
        this.to = to;
        this.body = body;
        this.subj = subj;
    }
}
